<template>
  <div class="Classification">
    <ul class="book-default">
      <li v-for="(item, index) in sameSort" :key="index">
        <a href="javascript:;">
          <img :src="item.book[0].imgSrc" alt="" />
          <p>{{ item.book[0].sort }}</p>
          <p class="last">
            <span>{{ item.book.length }}</span
            >本
          </p>
        </a>
      </li>
    </ul>
    <div class="footer">
      <p><span>9</span>本公开阅读</p>
      <div class="chakan"><a href="javascript:;">查看我的公开页面</a></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Classification",

  data() {
    return {
      sameSort: [],
      sortArr: ["诗歌散文", "青春文学", "宗教哲学", "政治军事", "历史"],
    };
  },
  props: ["mess"],
  mounted() {},

  methods: {
    fn() {
      this.sortArr.forEach((item) => {
        // console.log(item);
        let obj = {};
        obj.title = item;
        obj.book = [];
        this.mess.forEach((element) => {
          if (element.sort === obj.title) {
            obj.book.push(element);
          }
        });
        this.sameSort.push(obj);

        console.log(this.sameSort);
      });
    },
  },
  created() {
    this.fn();
  },
};
</script>

<style lang="less" scoped>
.Classification {
  width: 100%;
  // box-sizing: border-box;
  .book-default {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    li {
      width: 32%;
      // border:1px solid #ccc;
      height: 2.8rem;
      margin: 0.2rem 0 0.3rem 0;
      a {
        text-align: left;
        // display: block;
        img {
          width: 100%;
          height: 90%;
          display: block;
        }
        p {
          margin: 0;
          padding: 0;
          color: #000;
          text-align: center;
        }
      }
    }
    &::after {
      content: "";
      display: block;
      width: 32%;
    }
  }
  .footer {
    margin-top: 0.5rem;
    text-align: center;
    p {
      font-size: 0.12rem;
      color: #999;
      margin: 0;
      padding: 0;
    }
    .chakan {
      width: 100%;
      font-size: 0.13rem;
      margin-top: 0.1rem;
    }
  }
}
</style>